﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using Org.Eurekaa.DNJ.Settings;

namespace Org.Eurekaa.DNJ.UI.DNJSettings
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    [Serializable()]
    public class DNJSliderEvents : GenericSettingsObject
    {

        [Description("This event is triggered when the user starts sliding.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Start
        {
            get { return Get<UIEventFunction>("start"); }
            set { this["start"] = value; }
        }

        [Description("This event is triggered on every mouse move during slide. Use ui.value (single-handled sliders) to obtain the value of the current handle, $(..).slider('value', index) to get another handles' value. ")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Slide
        {
            get { return Get<UIEventFunction>("slide"); }
            set { this["slide"] = value; }
        }

        [Description("This event is triggered on slide stop, or if the value is changed programmatically (by the value method). Takes arguments event and ui. Use event.orginalEvent to detect whether the value changed by mouse, keyboard, or programmatically. Use ui.value (single-handled sliders) to obtain the value of the current handle, $(this).slider('values', index) to get another handle's value.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Change
        {
            get { return Get<UIEventFunction>("change"); }
            set { this["change"] = value; }
        }


        [Description("This event is triggered when the user stops sliding.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Stop
        {
            get { return Get<UIEventFunction>("stop"); }
            set { this["stop"] = value; }
        }



        public DNJSliderEvents()
        {
            this["start"] = new UIEventFunction();
            this["slide"] = new UIEventFunction();
            this["change"] = new UIEventFunction();
            this["stop"] = new UIEventFunction();
        }

        public string GetDefaultEventsScript()
        {
            String evtScript = String.Empty;
            foreach (UIEventFunction evt in Settings.Values)
            {
                if (!string.IsNullOrEmpty(evt.Name))
                {
                    evtScript += "if (!window." + evt.Name.Trim() + "){" + evt.Name.Trim() + " = new Function(\"return dnjDefaultEvent('" + evt.Name.Trim() + "')\");}";
                }
            }

            return evtScript;
        }
        public override string ToString()
        {
            return base.ToString();
        }


    }


}
